import config from '@/config'

export type ImageType = keyof typeof config.images

export const imageMap = new Map<ImageType, HTMLImageElement>()

// 返回 Promise[]。用于加载图片资源
export const imageResources = Object.entries(config.images).map(([key, value]) => {
    return new Promise<HTMLImageElement>((resolve) => {
        const img = new Image()
        img.src = value
        img.onload = () => {
            imageMap.set(key as ImageType, img)
            resolve(img)
        }
    })
})
